/* api */
import { getSparepartOccupancy } from '@src/api/SparePart';
/* model */
import MsgModel from '@model/MsgModel';
import Page from '@model/Page';
/* util */
import { message } from '@src/util/message';
import Log from '@src/util/log';
/* hooks */
import { useLoading } from '@hooks/useLoading';
/* vue */
import { Ref, ref } from 'vue';

// 获取项目列表数据
function useFetchOccupyTableList() {
  // 加载状态
  const { loading, showLoading, hideLoading } = useLoading();

  const dataList = ref([]);
  const dataListPageInfo: Ref<Page> = ref(new Page());

  const fetchTaskManageTableList = (searchParams: any) => {
    showLoading();

    return (
        getSparepartOccupancy(searchParams).then((res: any) => {
        if (MsgModel.isSuccess(res)) {
          dataListPageInfo.value = (res?.data || new Page()) as Page;
          dataList.value = (res?.data?.records || []);
        } else {
          message.error(res.message);
        }

        return dataList.value;

      }).catch((error: any) => {
        Log.error(error, fetchTaskManageTableList.name);
      }).finally(() => {
        hideLoading();
      })
    )
  }

  return {
    loading,
    dataList,
    dataListPageInfo,
    fetchTaskManageTableList,
  }
}


export {
  useFetchOccupyTableList
}
